"""
A server setup explicitly in Python
"""
import os

from wsgiappclient.middleware import make_app
from paste import httpexceptions
here = os.path.abspath(os.path.dirname(__file__))

import cherrypy

class Root:
    pass

if __name__ == '__main__':
    app_conf = {
        'base_url' : 'http://localhost:7300/',
        'template_directory' : os.path.join(here, 'wsgiappclient', 'xslt')
    }
    app = make_app(dict(), **(app_conf))
    app = httpexceptions.make_middleware(app, dict())

    global_conf = { 'engine.autoreload_on' : True,
                    'server.socket_port' : 7300,
                    'tools.proxy.on' : True,
                    'tools.proxy.base' : app_conf['base_url'],
                    'tools.proxy.local' : '',
                   }

    cherrypy.config.update({ 'global' : global_conf })
    
    conf = {'/' :  { 'tools.wsgiapp.on' : True,
                     'tools.wsgiapp.app' : app,
                     'tools.gzip.on' : True,
                     'tools.trailing_slash.on' : True,
                    },
            }

    cherrypy.tree.mount(Root(), '/', config=conf)
    cherrypy.server.quickstart()
    try:
        cherrypy.engine.start()
    except KeyboardInterrupt:
        cherrypy.engine.stop()
